package edu.hziee.servlet;

import edu.hziee.ProductionUtils.ProductionUtils;
import edu.hziee.model.production;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Iterator;

public class ListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        Collection<production> productions = ProductionUtils.getproductions();
        for (Iterator<production> iterator = productions.iterator(); iterator.hasNext(); ) {
            production Production = iterator.next();
            out.println(Production.getName() + "--" + Production.getPrice() + " <a href='abc.cart?id=" + Production.getId() + "'>购买</a><br>");
        }
    }
}
